/**
 * title:学子商城登录接口，采用promise封装数据库和模块化开发
 * author :王占胜
 * method：post
 * Elink: /login
 */

const express = require('express')
var loginRouter = express.Router()
const {chaxun} = require("../mysql.js")
loginRouter.post("/login",(req,res)=>{
    // 登录前查询
    console.log(req.body);

    let sql2 = "select uname,upwd from xz_user where uname = ?"
    chaxun(sql2, req.body.uname).then(restult => {
        // console.log(restult); 
        if(restult.length==0){
            res.send({
                code:203,
                message:'该用户名不存在'
            })
        }else if(restult[0].uname===req.body.uname && restult[0].upwd===req.body.upwd){
            res.send({
                code:200,
                message:'登录成功！'
            })
        }else{
            res.send({
                code:204,
                message:'用户名或者密码错误！'
            })
        }
    }).catch(err => {
        console.log(err);
    })
})


module.exports = {
    loginRouter
}